/**
  ************************************* Copyright ******************************
  * FileName   : spi_flash.h
  * Version    : v1.0
  * Author     : yychao
  * Date       : 2023-03-02
  * Description:
  * Function List:
  	1. ....
  	   <version>:
  <modify staff>:
  		  <data>:
   <description>:
  	2. ...
  ******************************************************************************
 */

#ifndef __SPI_FLASH_H_
#define __SPI_FLASH_H_


#include "stdint.h"
#include "spi.h"

#define BSP_SPI_DEV_FLASH_0 0
#define BSP_SPI_DEV_FLASH_1 1

#define W25Q80	0XEF13
#define W25Q16	0XEF14
#define W25Q32	0XEF15
#define W25Q64	0XEF16
#define W25Q128 0XEF17

#define SPIFLASH_REG_SR_SPR		(1 << 7)
#define SPIFLASH_REG_SR_RV		(1 << 6)
#define SPIFLASH_REG_SR_TB		(1 << 5)
#define SPIFLASH_REG_SR_BP2		(1 << 4)
#define SPIFLASH_REG_SR_BP1		(1 << 3)
#define SPIFLASH_REG_SR_BP0		(1 << 2)
#define SPIFLASH_REG_SR_WEL		(1 << 1)
#define SPIFLASH_REG_SR_BUSY	(1 << 0)

#define SPIFLASH_WriteEnable				0x06
#define SPIFLASH_WriteDisable				0x04
#define SPIFLASH_ReadStatusReg				0x05
#define SPIFLASH_WriteStatusReg				0x01
#define SPIFLASH_ReadData					0x03
#define SPIFLASH_FastReadData				0x0B
#define SPIFLASH_FastReadDual				0x3B
#define SPIFLASH_PageProgram				0x02
#define SPIFLASH_BlockErase					0xD8
#define SPIFLASH_SectorErase				0x20
#define SPIFLASH_ChipErase					0xC7
#define SPIFLASH_PowerDown					0xB9
#define SPIFLASH_ReleasePowerDown			0xAB
#define SPIFLASH_DeviceID					0xAB
#define SPIFLASH_ManufactDeviceID			0x90
#define SPIFLASH_JedecDeviceID				0x9F



uint16_t SPIFLASH_init(  uint8_t devNum );
unsigned short int SPIFLASH_readID( uint8_t devNum );
unsigned char SPIFLASH_readSR( uint8_t devNum );
void SPIFLASH_writeSR( uint8_t devNum,unsigned char sr );
void SPIFLASH_writeEnable( uint8_t devNum );
void SPIFLASH_writeDisable( uint8_t devNum );
void SPIFLASH_writeNoCheck(uint8_t devNum, unsigned char* pBuffer, unsigned long int WriteAddr, unsigned short int NumByteToWrite );
uint8_t SPIFLASH_read(uint8_t devNum, unsigned char* pBuffer, unsigned long int ReadAddr, unsigned short int NumByteToRead );
uint8_t SPIFLASH_write( uint8_t devNum,unsigned char* pBuffer, unsigned long int WriteAddr, unsigned short int NumByteToWrite );
void SPIFLASH_eraseChip( uint8_t devNum );
void SPIFLASH_eraseSector( uint8_t devNum,unsigned long int Dst_Addr );
void SPIFLASH_waitBusy( uint8_t devNum);
void SPIFLASH_powerDown( uint8_t devNum);
void SPIFLASH_wakeUp( uint8_t devNum );


#endif

